package com.spider.util;

import java.util.Properties;

import org.apache.log4j.Logger;

/**
 * 配置文件SpiderProperties
 *
 */
public class SpiderProperties {
    private static final Logger log = Logger.getLogger(SpiderProperties.class);
    private static Properties pro=new Properties();
    private static final String configName="spider.properties";
    
    static{
        try {
            log.info("start load spider.properties");
            pro.load(SpiderProperties.class.getClassLoader().getResourceAsStream(configName));
            log.info("end load spider.properties");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     * 获得配置文件中指定key对应的value，如果没有此key则返回空字符
     */
    public static String getString(String key){
        return getString(key, "");
    }
    /**
     * 获得配置文件中指定key对应的value，如果没有此key则返回指定的默认值
     */
    public static String getString(String key,String defaultValue){
        String result=defaultValue;
        try{
            result=pro.getProperty(key,result);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

}
